<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:fo="http://www.w3.org/1999/XSL/Format">
	
	<xsl:include href="main.xsl"/>

	<!--
	additional scripts
	-->
	<xsl:template mode="script" match="/">
		<script type="text/javascript" language="JavaScript">
			function deleteAsociation(url)
			{
				if(confirm("Delete the selected asociation ?"))
					sendUrl(url);
			}
		</script>
	</xsl:template>
	
	<!--
	page content
	-->
	<xsl:template name="content">
		<xsl:call-template name="formLayout">
			<xsl:with-param name="title" select="/root/gui/strings/categoryAreaManagement"/>
			<xsl:with-param name="content">
				<xsl:call-template name="form"/>
			</xsl:with-param>
			 <xsl:with-param name="menu">contentAdmin</xsl:with-param>
                         <!--
			<xsl:with-param name="buttons">
				<button class="content" onclick="load('{/root/gui/locService}/admin')"><xsl:value-of select="/root/gui/strings/back"/></button>
			</xsl:with-param>
                        -->
		</xsl:call-template>
	</xsl:template>
	
	<!--
	form
	-->
	<xsl:template name="form">
		<xsl:variable name="lang" select="/root/gui/language"/>
		<form name="areaCategoryUpdateForm" id="areaCategoryUpdateForm" accept-charset="UTF-8" action="{/root/gui/locService}/area_category.update" method="post">
			<input type="hidden" id="new_relation" name="new_relation" value="false" />
			<table border="0" width="60%" cellpadding="2" cellspacing="0">
				<tr>
					<th class="padded"><xsl:value-of select="/root/gui/strings/organization"/></th>
					<td class="padded">
						<select style="width:300px" class="content" size="1" name="id_organization" onchange="document.getElementById('new_relation').value='false';document.getElementById('areaCategoryUpdateForm').submit();">
							<option value="" >- - <xsl:value-of select="/root/gui/strings/organization"/> - - </option>
							<xsl:for-each select="/root/record/organizations/response/record">
								<option value="{id_organization}">
									<xsl:if test="/root/request/id_organization=id_organization">
										<xsl:attribute name="selected"/>
									</xsl:if>
									<xsl:value-of select="."/>
								</option>
							</xsl:for-each>
						</select>
					</td>
				</tr>
				<xsl:if test="/root/record/branches/response/record">
				<tr>
					<th class="padded"><xsl:value-of select="/root/gui/strings/branch"/></th>
					<td class="padded">
						<select style="width:300px" class="content" size="1" name="id_branch" onchange="document.getElementById('new_relation').value='false';document.getElementById('areaCategoryUpdateForm').submit();">
							<option value="" >- - <xsl:value-of select="/root/gui/strings/branch"/> - - </option>
							<xsl:for-each select="/root/record/branches/response/record">
								<option value="{id_branch}">
									<xsl:if test="/root/request/id_branch=id_branch">
										<xsl:attribute name="selected"/>
									</xsl:if>
									<xsl:value-of select="."/>
								</option>
							</xsl:for-each>
						</select>
					</td>
				</tr>
				</xsl:if>
				<xsl:if test="/root/record/area/response/record">
				<tr>
					<th class="padded"><xsl:value-of select="/root/gui/strings/areas"/></th>
					<td class="padded">
						<select style="width:300px" class="content" size="1" name="id_area" onchange="document.getElementById('new_relation').value='false';document.getElementById('areaCategoryUpdateForm').submit();">
							<option value="" >- - <xsl:value-of select="/root/gui/strings/areas"/> - - </option>
							<xsl:for-each select="/root/record/area/response/record">
								<option value="{id_area}">
									<xsl:if test="/root/request/id_area=id_area">
										<xsl:attribute name="selected"/>
									</xsl:if>
									<xsl:value-of select="."/>
								</option>
							</xsl:for-each>
						</select>
					</td>
				</tr>
					<xsl:if test="/root/request/id_area">
					<tr>
						<th class="padded">
							<xsl:value-of select="/root/gui/strings/category"/>
						</th>
						<td class="padded">
							<select style="width:300px" class="content" name="id_category" id="id_category">
								<xsl:for-each select="/root/gui/categories/record">
									<option value="{id}">
										<xsl:if test="/root/request/id_area = id_category">
											<xsl:attribute name="selected"/>
										</xsl:if>
										<xsl:value-of select="label/child::*[name() = $lang]"/>
									</option>
								</xsl:for-each>
							</select><br/>
							<button class="content" onclick="javascript: document.getElementById('new_relation').value='true';document.areaCategoryUpdateForm.submit();"><xsl:value-of select="/root/gui/strings/save"/></button>
						
						</td>
					</tr>
					<tr><td height="30"></td></tr>
					<tr>
						<td align="center" colspan="2">				
							<table width="100%" border="0" cellpadding="4">
								<tr>
									<th class="padded, bottom_border"><xsl:value-of select="/root/gui/strings/name"/></th>
									<th class="padded"><xsl:value-of select="/root/gui/strings/operation"/></th>
								</tr>
								<xsl:for-each select="/root/gui/categories/record">
									<xsl:variable name="catName" select="label/child::*[name() = $lang]"/>
									<xsl:variable name="catId" select="id"/>
									<xsl:for-each select="/root/record/relations/response/record">
										<xsl:if test="$catId = id_category">
										<tr>
											<td class="padded, bottom_border"><xsl:value-of select="$catName"/></td>
											<td class="padded" width="150px">
												<button class="content" onclick="document.getElementById('new_relation').value='false';deleteAsociation('{/root/gui/locService}/area_category.remove?id_area={id_area}&amp;id_category={id_category}' )"><xsl:value-of select="/root/gui/strings/delete"/></button>
											</td>
										</tr>
										</xsl:if>
									</xsl:for-each>
								</xsl:for-each>
							</table>
						</td>
					</tr>		
					</xsl:if>
				</xsl:if>
			</table>
		</form>
	</xsl:template>
	
</xsl:stylesheet>
